#ifndef RESOURCE_DATABASE_H
#define RESOURCE_DATABASE_H

#include <map>
#include <string>

#include "boost_filesystem.h"
#include "boost/noncopyable.hpp"
#include "sfml/Graphics.hpp"

class ResImage;
class ResSound;
typedef boost::shared_ptr<ResImage> ResImagePtr;
typedef boost::shared_ptr<ResSound> ResSoundPtr;

//This will be in file with all images data containing: ID, file name, rows, columns
#define IMG_TREE 0
#define IMG_SANTA 1
#define IMG_HAND 2
#define IMG_INVENTORY 3
#define IMG_BULLET 4
#define IMG_TEST_ITEM 5
#define IMG_CURSOR_DEFAULT 6

class ResourceDatabase : public boost::noncopyable
{
public:
	static void initialise(std::string saveName);
    static void cleanUpAll();
    static void cleanUpSounds();
    static void cleanUpImages();

    void update(float delta);
    void save(std::string saveName) const;

    void addImage(int id, int rows, int columns, std::string filename);
    void deleteImage(int id);
    void deleteImage(std::string filename);
    const ResImagePtr getImage(int id);

    void addSound(int id, std::string filename, char flags, sf::Vector2i position, float volume = 1.0f, float pitch = 1.0f);
    void deleteSound(int id);
    void deleteSound(std::string filename);
    const ResSoundPtr getSound(int id);

    static ResourceDatabase& get();
private:
	ResourceDatabase();

    bool readFile(std::string saveName);
    void writeFile(std::string saveName) const;

	static ResourceDatabase instance;
	static bool initialised;

    typedef std::map<int, ResImagePtr> img_map;
    typedef img_map::iterator image_it;
    img_map images;    
    typedef std::map<int, ResSoundPtr> sound_map;
    typedef sound_map::iterator sound_it;
    sound_map sounds;
};

#endif